﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Configuration;

namespace RAgency.Manager
{
    public partial class MAccess : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void AccessOn(object sender, EventArgs e)
        {
            if (RButtonAction1.Checked)
            {
                SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ApplicationServices"].ConnectionString);
                try
                {
                    SqlCommand comm = new SqlCommand("UPDATE users SET access='11.11.1999' WHERE login='" + DDList.Text + "'", conn);
                    conn.Open();
                    comm.ExecuteReader();
                    ActionResult.Text = "Доступ предоставлен (одноразовый).";
                }
                catch (Exception ex)
                {
                    ActionResult.Text = ex.Message;
                }
                finally
                {
                    conn.Close();
                }
            }
            else if (RButtonAction2.Checked)
            {
                SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ApplicationServices"].ConnectionString);
                try
                {
                    SqlCommand comm = new SqlCommand("UPDATE users SET access='" + DateTime.Now.AddDays(Convert.ToInt32(DaysTBox.Text)) + "' WHERE login='" + DDList.Text + "'", conn);
                    conn.Open();
                    comm.ExecuteReader();
                    ActionResult.Text = "Доступ предоставлен (на N дней).";
                }
                catch (Exception ex)
                {
                    ActionResult.Text = ex.Message;
                }
                finally
                {
                    conn.Close();
                }
            }
        }
    }
}